<template lang="html">
    <div class="box">
          <div class="header">
                <el-tabs v-model="activeName" @tab-click="switchTabBar()">
                  <el-tab-pane label="邦保盒子供应奖励" name="1"></el-tab-pane>
                  <el-tab-pane label="油品结算" name="2"></el-tab-pane>
                  <el-tab-pane label="养护品结算" name="3"></el-tab-pane>
                </el-tabs>
          </div>

          <div class="body" v-show="activeName==1">
                <el-form class="filterCondition demo-form-inline" ref="form"  :inline="true" label-width="80px">
                    <el-input placeholder="供应商名称/车主名称" v-model="keyword" style="width: 420px;">
                      <el-button slot="append" style="width: 120px;" @click="switchTab()">搜索</el-button>
                    </el-input>
                    <el-form-item label="时间段" style="margin-bottom: 0;width: 520px;">
                      <el-date-picker v-model="intervalTime" type="daterange" align="right" unlink-panels range-separator="-"
                        start-placeholder="开始日期" end-placeholder="结束日期" style="width: 100%;"
                        value-format="yyyy-MM-dd HH:mm:ss" >
                      </el-date-picker>
                    </el-form-item>
                </el-form>
                <!--  -->
                <div class="table_box">
                    <el-table :data="tableData.list" style="width: 100%">
                        <el-table-column  prop="sm_name"  align="center" label="供应商名称" >
                          <!-- <template lang="html" slot-scope="scope">
                              <el-popover trigger="hover" placement="top">
                                  <p>姓名: {{ scope.row.share_name }}</p>
                                  <div slot="reference" class="name-wrapper">
                                    <el-tag size="medium">{{ scope.row.share_name }}</el-tag>
                                  </div>
                              </el-popover>
                          </template> -->
                        </el-table-column>
                        <el-table-column  prop="refund_price"  align="center" label="奖励金额" ></el-table-column>
                        <el-table-column  prop="user_name"  align="center" label="车主姓名" >
                          <!-- <template lang="html" slot-scope="scope">
                              <el-popover trigger="hover" placement="top">
                                  <p>姓名: {{ scope.row.share_name }}</p>
                                  <div slot="reference" class="name-wrapper">
                                    <el-tag size="medium">{{ scope.row.share_name }}</el-tag>
                                  </div>
                              </el-popover>
                          </template> -->
                        </el-table-column>
                        <el-table-column  prop="car_type"  align="center" label="车型" >
                            <template lang="html" slot-scope="scope">
                                <el-popover trigger="hover" placement="top">
                                    <p>{{ scope.row.car_brand }}--{{ scope.row.car_type }}</p>
                                    <div slot="reference" class="name-wrapper">
                                      <el-tag size="medium">{{ scope.row.car_type }}</el-tag>
                                    </div>
                                </el-popover>
                            </template>
                        </el-table-column>
                        <el-table-column  prop="create_time"  align="center" label="时间" ></el-table-column>
                    </el-table>
                </div>
          </div>
          <div class="body" v-show="activeName==2">
                <el-form class="filterCondition demo-form-inline" ref="form"  :inline="true" label-width="80px">
                    <el-input placeholder="供应商名称" v-model="keyword" style="width: 420px;">
                      <el-button slot="append" style="width: 120px;" @click="switchTab()">搜索</el-button>
                    </el-input>
                    <el-form-item label="时间段" style="margin-bottom: 0;width: 520px;">
                      <el-date-picker v-model="intervalTime" type="daterange" align="right" unlink-panels range-separator="-"
                        start-placeholder="开始日期" end-placeholder="结束日期" style="width: 100%;"
                        value-format="yyyy-MM-dd HH:mm:ss" >
                      </el-date-picker>
                    </el-form-item>
                </el-form>
                <div class="table_box">
                    <el-table :data="tableData.list" style="width: 100%">
                        <el-table-column  prop="sm_name"  align="center" label="供应商名称" >
                          <!-- <template lang="html" slot-scope="scope">
                              <el-popover trigger="hover" placement="top">
                                  <p>姓名: {{ scope.row.share_name }}</p>
                                  <div slot="reference" class="name-wrapper">
                                    <el-tag size="medium">{{ scope.row.share_name }}</el-tag>
                                  </div>
                              </el-popover>
                          </template> -->
                        </el-table-column>
                        <el-table-column  prop=""  align="center" label="结算金额" >
                            <template slot-scope="scope">
                              <el-button size="mini" type="primary" @click="handleDetail(scope.row)" plain>{{scope.row.money}}</el-button>
                            </template>
                        </el-table-column>
                        <el-table-column  align="center" label="发票" >
                              <template slot-scope="scope">
                                  <img :preview="scope.row.tax" class="preview-img" :src="scope.row.tax" alt="">
                              </template>
                        </el-table-column>
                        <el-table-column align="center" label="运费金额" >
                            <template slot-scope="scope">
                              <el-button size="mini" type="primary" @click="handleDetail(scope.row)" plain>{{scope.row.freight}}</el-button>
                            </template>
                        </el-table-column>
                        <el-table-column align="center" label="总金额" >
                              <template slot-scope="scope">
                                <el-button size="mini" type="primary" @click="handleDetail(scope.row)" plain>{{scope.row.total_money}}</el-button>
                              </template>
                        </el-table-column>
                        <el-table-column  prop="create_time"  align="center" label="申请时间" ></el-table-column>
                        <el-table-column  prop="audit_time"  align="center" label="审核时间" ></el-table-column>
                        <el-table-column  prop="audit_person"  align="center" label="审核人" ></el-table-column>
                    </el-table>
                </div>
          </div>
          <div class="body" v-show="activeName==3">
                <el-form class="filterCondition demo-form-inline" ref="form"  :inline="true" label-width="80px">
                    <el-input placeholder="供应商名称" v-model="keyword" style="width: 420px;">
                      <el-button slot="append" style="width: 120px;" @click="switchTab()">搜索</el-button>
                    </el-input>
                    <el-form-item label="时间段" style="margin-bottom: 0;width: 520px;">
                      <el-date-picker v-model="intervalTime" type="daterange" align="right" unlink-panels range-separator="-"
                        start-placeholder="开始日期" end-placeholder="结束日期" style="width: 100%;"
                        value-format="yyyy-MM-dd HH:mm:ss" >
                      </el-date-picker>
                    </el-form-item>
                </el-form>
                <div class="table_box">
                    <el-table :data="tableData.list" style="width: 100%">
                        <el-table-column  prop="sm_name"  align="center" label="供应商名称" >
                          <!-- <template lang="html" slot-scope="scope">
                              <el-popover trigger="hover" placement="top">
                                  <p>姓名: {{ scope.row.share_name }}</p>
                                  <div slot="reference" class="name-wrapper">
                                    <el-tag size="medium">{{ scope.row.share_name }}</el-tag>
                                  </div>
                              </el-popover>
                          </template> -->
                        </el-table-column>
                        <el-table-column  align="center" label="结算金额" >
                            <template slot-scope="scope">
                              <el-button size="mini" type="primary" @click="handleDetail(scope.row)" plain>{{scope.row.money}}</el-button>
                            </template>
                        </el-table-column>
                        <el-table-column  align="center" label="发票" >
                              <template slot-scope="scope">
                                  <img :preview="scope.row.tax" class="preview-img" :src="scope.row.tax" alt="">
                              </template>
                        </el-table-column>
                        <el-table-column   align="center" label="运费金额" >
                            <template slot-scope="scope">
                              <el-button size="mini" type="primary" @click="handleDetail(scope.row)" plain>{{scope.row.freight}}</el-button>
                            </template>
                        </el-table-column>
                        <el-table-column  align="center" label="总金额" >
                            <template slot-scope="scope">
                              <el-button size="mini" type="primary" @click="handleDetail(scope.row)" plain>{{scope.row.total_money}}</el-button>
                            </template>
                        </el-table-column>
                        <el-table-column  prop="create_time"  align="center" label="申请时间" ></el-table-column>
                        <el-table-column  prop="audit_time"  align="center" label="审核时间" ></el-table-column>
                        <el-table-column  prop="audit_person"  align="center" label="审核人" ></el-table-column>
                    </el-table>
                </div>
          </div>
          <p  class="summary">{{tableData.total}}</p>
          <!--  -->
          <div class="page_box">
              <el-pagination class="page" layout="prev, pager, next"
                @current-change="switchPage" :current-page="currentPage" :page-count='tableData.rows' >
              </el-pagination>
          </div>

          <el-dialog title="油品结算详情" :visible.sync="aVisible">
                <el-table :data="gridData">
                      <el-table-column label="油品名称" align="center">
                          <template slot-scope="scope">
                              <p v-for="item,index in scope.row.detail">{{item.materiel}}</p>
                          </template>
                      </el-table-column>
                      <el-table-column label="数量" width="100" align="center">
                          <template slot-scope="scope">
                              <p v-for="item,index in scope.row.detail">{{item.num}}</p>
                          </template>
                      </el-table-column>
                      <el-table-column property="settlement_price" label="结算金额" align="center"></el-table-column>
                      <el-table-column label="运费图片">
                          <template slot-scope="scope">
                              <img :preview="scope.row.freight_pic" class="preview-img" :src="scope.row.freight_pic" alt="">
                          </template>
                      </el-table-column>
                      <el-table-column property="freight" label="运费金额" align="center"></el-table-column>
                      <el-table-column property="receipt_time" label="时间" align="center"></el-table-column>
                </el-table>
          </el-dialog>
          <el-dialog title="养护品结算详情" :visible.sync="bVisible">
                <el-table :data="gridData">
                      <el-table-column property="receipt_time" label="时间" align="center"></el-table-column>
                      <el-table-column property="goods_name" label="名称" align="center"></el-table-column>
                      <el-table-column property="stand" label="规格" align="center"></el-table-column>
                      <!-- <el-table-column label="运费图片" align="center">
                          <template slot-scope="scope">
                              <img :preview="scope.row.freight_pic" class="preview-img" :src="scope.row.freight_pic" alt="">
                          </template>
                      </el-table-column> -->
                      <el-table-column property="freight" label="运费金额" align="center"></el-table-column>
                </el-table>
          </el-dialog>

    </div>
</template>

<script>
export default {
  data() {
      return {
        token: this.$store.state.user.token3,
        activeName: '1',
        currentActive:'1',
        aVisible: false,
        bVisible: false,
        keyword: '',
        tableData: [],
        gridData: [],
        intervalTime: [],
        currentPage:1
      }
  },
  created(){
    this.switchTab()
    this.$preview.on('imageLoadComplete',(e,item)=>{
    	this.$preview.self.template.style.zIndex = 99999
    })
  },
  methods: {
      initSetData(){
        this.keyword = ''
        this.tableData = []
        this.intervalTime = []
      },
      switchTabBar(){
          if(this.activeName == this.currentActive){
            return false;
          }else{
             this.initSetData()
             this.switchTab()
             this.currentActive = this.activeName
          }
      },
      switchTab(n=this.activeName,p=1){
        var jsonData = {
          token: this.token,
          key: this.keyword,
          start_time: (this.intervalTime && this.intervalTime[0]) || '',
          end_time: (this.intervalTime && this.intervalTime[1]) || '',
          page: p
        }
        this.currentPage = p;
        switch (n) {
          case '1':     //邦保盒子供应奖励
            this.$http3.smObdIncList(jsonData)
            .then(this.resultFn())
            break;
          case '2':    //油品结算
            this.$http3.smOilInclist(jsonData)
            .then(this.resultFn())
            break;
          case '3':    //养护品结算
            this.$http3.smFreeInclist(jsonData)
            .then(this.resultFn())
            break;
          }

      },

      handleDetail(e){
          if(this.activeName == 2){
              this.aVisible = true
          }else if(this.activeName == 3){
              this.bVisible = true
          }
          this.$http3.getSmIncDetail({
            token: this.token,
            id: e.id,
            type: e.type
          }).then(res=>{
            this.gridData =
            res.data.code == 1?
            res.data.data : []

            this.$previewRefresh();
          })
      },

      resultFn(){
        return function(res) {
            if(res){
              this.tableData =
              res.data.code ===1 ?
              this.tableData = res.data.data:[];
            }
            this.$previewRefresh();
        }.bind(this)
      },

      switchPage(e){
          this.switchTab(this.activeName,e)
      }
  }
}
</script>

<style lang="css" scoped>
@import "../../../my-style/app.css";
/deep/ .el-input-group__append, .el-input-group__prepend{
  background-color: #3498E9;
  border: none;
  color: white;
}
/deep/ .table_box .preview-img{
  display:block;
  width: 100%;
  height: 30px;
}
.page_box{
  text-align: center;
}
</style>
